package ops.view.forms.component;

import javax.swing.JComponent;
import javax.swing.JLabel;

/**
 * Abstract class representing a basic form input.
 * A form input is basically made of a label and a component that accepts user's input.
 * Check the subclasses for more info.
 * @author flavio
 */
public abstract class FormInput {

	private String label;
	private boolean required = false;
	
	protected FormInput(String label, boolean required) {
		this.label = label;
		this.required = required;
	}
	
	/**
	 * @return true if this input is required or false if not.
	 * Very useful for form validation.
	 */
	public boolean isRequired() {
		return required;
	}

	/**
	 * Renders a JLabel.
	 */
	public JLabel getLabelComponent() {
		return new JLabel(label);
	}
	
	/**
	 * Overriding this method allows you to add custom validation to your input.
	 * @return
	 */
	public boolean validate() {
		return true;
	}
	
	/**
	 * @return the component that will accept input from the user. 
	 */
	public abstract JComponent getInputComponent();
	
	/**
	 * @return the value input'ed by the user. 
	 */
	public abstract Object getInputValue();
	
	/**
	 * Changes the input value.
	 * @param value
	 */
	public abstract void setInputValue(Object value);
	
	/**
	 * Clears the data.
	 */
	public abstract void clearInput();
}
